package courseSystem.data;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FO {
    public void logFile(String data) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        String path = "log" + formatter.format(date) + ".txt";
        formatter = new SimpleDateFormat("HH:mm:ss z");
        try {
            java.io.File file = new java.io.File(path);
            FileOutputStream fos;
            if (!file.exists()) {
                file.createNewFile();
                fos = new FileOutputStream(file);
            } else {
                fos = new FileOutputStream(file, true);
            }
            OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
            osw.write(formatter.format(date) + ':' + data + "\r\n");
            osw.close();
        } catch (Exception e) {
            System.out.println("日志模块:" + e.getMessage());
        }
    }
}
